
<!doctype html>
<html>
<head>
    <title>Demo &raquo; Add widgets dynamically &raquo; gridster.js</title>
    <link rel="stylesheet" type="text/css" href="../dist/jquery.gridster.css">
    <link rel="stylesheet" type="text/css" href="../assets/demo.css">
</head>

<body>

<h1>Add widgets dynamically</h1>
<p>Create a grid adding widgets from an Array (not from HTML) using <code>add_widget</code> method. Widget position (col, row) not specified.</p>

<div class="gridster">
    <ul></ul>
</div>

<script type="text/javascript" src="../assets/jquery.js"></script>
<script src="../dist/jquery.gridster.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript" id="code">
    var gridster;
    $(function(){
        gridster = $(".gridster > ul").gridster({
            widget_margins: [1, 1],
            widget_base_dimensions: [50, 50]
        }).data('gridster');

        var widgets = [
            ['<li>0zhaochao</li>', 3, 3],
            ['<li>1</li>', 3, 2],
            ['<li>2</li>', 3, 2],
            ['<li>3</li>', 2, 1],
            ['<li>4</li>', 4, 1],
            ['<li>5</li>', 1, 2],
            ['<li>6</li>', 2, 1],
            ['<li>7</li>', 3, 2],
            ['<li>8</li>', 1, 1],
            ['<li>9</li>', 2, 2],
            ['<li>10</li>', 1, 3]
        ];

        $.each(widgets, function(i, widget){
            gridster.add_widget.apply(gridster, widget)
        });

    });
</script>
</body>
</html>
